package dz.chuxin.framework.widget.rowview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import dz.chuxin.framework.R;
import dz.chuxin.framework.util.DensityUtil;

/**
 * 普通的RowView，包括Icon、Label和右箭头
 * Created by chuxin on 2016/7/17.
 */
public class NormalRowView extends BaseRowView {

    private Context mContext;

    private ImageView mIconImage;
    private TextView mLabelText;
    private ImageView mArrowImage;

    public NormalRowView(Context context) {
        this(context, null);
    }

    public NormalRowView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public NormalRowView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;
        // NormalRowView限定高度为56dp
        ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                DensityUtil.dp2px(mContext, 56));
        setLayoutParams(layoutParams);
    }

    @Override
    protected void initialize() {
        mIconImage = (ImageView) findViewById(R.id.widget_row_icon);
        mLabelText = (TextView) findViewById(R.id.widget_row_label);
        mArrowImage = (ImageView) findViewById(R.id.widget_row_arrow);
    }

    @Override
    protected int getRowLayoutResource() {
        return R.layout.widget_normal_row;
    }

    @Override
    public void stuffData(BaseRowDescriptor rowDescriptor, OnRowClickListener listener) {
        super.stuffData(rowDescriptor, listener);
        NormalRowDescriptor normalRowDescriptor = (NormalRowDescriptor) rowDescriptor;

        setPadding(DensityUtil.dp2px(mContext, normalRowDescriptor.getHorizontalPadding()),
                DensityUtil.dp2px(mContext, normalRowDescriptor.getVerticalPadding()),
                DensityUtil.dp2px(mContext, normalRowDescriptor.getHorizontalPadding()),
                DensityUtil.dp2px(mContext, normalRowDescriptor.getVerticalPadding()));

        if (normalRowDescriptor.getIconResource() == 0)
            mIconImage.setVisibility(GONE);
        mIconImage.setImageResource(normalRowDescriptor.getIconResource());
        mLabelText.setText(normalRowDescriptor.getRowLabel());
        if (!rowDescriptor.isClickEnable) mArrowImage.setVisibility(View.GONE);
    }
}
